package com.ruoyi.maode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.exception.UtilException;
import com.ruoyi.common.utils.ExceptionUtil;
import com.ruoyi.maode.domain.dto.QuerySupplierDTO;
import com.ruoyi.maode.domain.entity.Supplier;
import com.ruoyi.maode.mapper.SupplierMapper;
import com.ruoyi.maode.service.SupplierService;
import com.ruoyi.web.util.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

/**
 * 供应商实现类
 * @author zhangwenqiang
 */
@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements SupplierService {
    @Autowired
    private SupplierMapper supplierMapper;

    @Override
    public int add(Supplier supplier) {
        // 查询供应商是否存在
        Supplier supplierNew = supplierMapper.selectOne(new LambdaQueryWrapper<Supplier>().eq(Supplier::getSupplierName, supplier.getSupplierName()));
        if (supplierNew != null) {
            throw new UtilException("供应商已存在，请确认！");
        }
        int insert = supplierMapper.insert(supplier);
        return insert;
    }

    @Override
    public Page<Supplier> selectSupplierList(PageQuery<QuerySupplierDTO> dto) {
        Page page = new Page<Supplier>(dto.getPage(), dto.getPageSize());
        QuerySupplierDTO queryPartDTO = dto.getData();
        return supplierMapper.selectSupplierList(page,queryPartDTO);
    }
}
